package indi.cc.demo.validator.controller;

import indi.cc.demo.validator.model.ValidatorModel;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/test")
public class ValidatorController {
    @PostMapping("/validator")
    @ResponseBody
    public ResponseEntity testValidator(@Validated @RequestBody ValidatorModel model) {
//        if (bindingResult.hasFieldErrors()) {
//            for (FieldError fieldError : bindingResult.getFieldErrors()) {
//                System.out.println(fieldError.getDefaultMessage());
//            }
//        }
//        System.out.println("controller");
        return ResponseEntity.ok(model);
    }
}
